import {applicationFormUrlEncodedHeader, doGet, doPost} from "@/net/axios-request.ts";
import type {Permission} from "@/net/controller/rbac-controller.ts";
import {userTokenHeader} from "@/utils/auth-utils.ts";

export interface Level {
    levelId: number,
    levelName: string,
    postCount: number,
    replyCount: number,
    essenceCount: number,
    minExperience: number,
    createdAt: string,
    updatedAt: string,
    iconUrl: string,
    title: string
}

export async function getAllLevelPermissions() {
    return (await doGet<{[_: string]: { level: Level, permissions: Permission[]}}>("/api/level-permission/all", {...userTokenHeader()}, {})).data
}

export async function bindLevelPermissions(levelId: number, permissionId: number) {
    return (await doPost("/api/level-permission/bind", {...userTokenHeader(), ...applicationFormUrlEncodedHeader}, { levelId: levelId, permissionId: permissionId })).data
}

export async function unbindLevelPermissions(levelId: number, permissionId: number) {
    return (await doPost("/api/level-permission/unbind", {...userTokenHeader(), ...applicationFormUrlEncodedHeader}, { levelId: levelId, permissionId: permissionId })).data
}